home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Getting Started / Drawing a String / GDITEST9.dpr
Encoding:
Text File  |  2003-10-15  |  2.5 KB  |  100 lines

  1. program GDITEST9;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   pen: TGPPen;
  14.   brush : TGPSolidBrush;
  15.   fontFamily: TGPFontFamily;
  16.   font: TGPFont;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.   pen:= TGPPen.Create(MakeColor(255, 0, 0, 255),8);
  20.  
  21.   brush:= TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
  22.   fontFamily:= TGPFontFamily.Create('Times New Roman');
  23.   font:= TGPFont.Create(fontFamily, 24, FontStyleRegular, UnitPixel);
  24.   graphics.DrawString('Hello World!', -1, font, MakePoint(0.0,0.0), brush);
  25.  
  26.   pen.Free;
  27.   graphics.Free;
  28.   brush.Free;
  29.   fontFamily.Free;
  30.   font.Free;
  31.  
  32. end;
  33.  
  34.  
  35. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  36. var
  37.   Handle: HDC;
  38.   ps: PAINTSTRUCT;
  39. begin
  40.   case message of
  41.     WM_PAINT:
  42.       begin
  43.         Handle := BeginPaint(Wnd, ps);
  44.         OnPaint(Handle);
  45.         EndPaint(Wnd, ps);
  46.         result := 0;
  47.       end;
  48.  
  49.     WM_DESTROY:
  50.       begin
  51.         PostQuitMessage(0);
  52.         result := 0;
  53.       end;
  54.  
  55.    else
  56.       result := DefWindowProc(Wnd, message, wParam, lParam);
  57.    end;
  58. end;
  59.  
  60. var
  61.   hWnd     : THandle;
  62.   Msg      : TMsg;
  63.   wndClass : TWndClass;
  64. begin
  65.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  66.    wndClass.lpfnWndProc    := @WndProc;
  67.    wndClass.cbClsExtra     := 0;
  68.    wndClass.cbWndExtra     := 0;
  69.    wndClass.hInstance      := hInstance;
  70.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  71.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  72.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  73.    wndClass.lpszMenuName   := nil;
  74.    wndClass.lpszClassName  := 'GettingStarted';
  75.  
  76.    RegisterClass(wndClass);
  77.  
  78.    hWnd := CreateWindow(
  79.       'GettingStarted',       // window class name
  80.       'Drawing a String',     // window caption
  81.       WS_OVERLAPPEDWINDOW,    // window style
  82.       Integer(CW_USEDEFAULT), // initial x position
  83.       Integer(CW_USEDEFAULT), // initial y position
  84.       Integer(CW_USEDEFAULT), // initial x size
  85.       Integer(CW_USEDEFAULT), // initial y size
  86.       0,                      // parent window handle
  87.       0,                      // window menu handle
  88.       hInstance,              // program instance handle
  89.       nil);                   // creation parameters
  90.  
  91.    ShowWindow(hWnd, SW_SHOW);
  92.    UpdateWindow(hWnd);
  93.  
  94.    while(GetMessage(msg, 0, 0, 0)) do
  95.    begin
  96.       TranslateMessage(msg);
  97.       DispatchMessage(msg);
  98.    end;
  99. end.
  100.